using Core;
using System;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;

public class OpenExplorer
{
    [MenuItem("Mini Tools/Explorer/Open PersistentDataPath", false)]
    [MenuItem("Assets/Mini Tools/Explorer/Open PersistentDataPath", false)]
    public static void OpenPersistentDataPath()
    {
        Execute(Application.persistentDataPath);
    }

    [MenuItem("Mini Tools/Explorer/Open StreamingAssetsPath", false)]
    [MenuItem("Assets/Mini Tools/Explorer/Open StreamingAssetsPath", false)]
    public static void OpenStreamingAssetsPath()
    {
        Execute(Application.streamingAssetsPath);
    }

    [MenuItem("Mini Tools/Explorer/Open DataPath", false)]
    [MenuItem("Assets/Mini Tools/Explorer/Open DataPath", false)]
    public static void OpenDataPath()
    {
        Execute(Application.dataPath);
    }

    [MenuItem("Mini Tools/Explorer/Open TemporaryCachePath", false)]
    [MenuItem("Assets/Mini Tools/Explorer/Open TemporaryCachePath", false)]
    public static void OpenTemporaryCachePath()
    {
        Execute(Application.temporaryCachePath);
    }

    private static void Execute(string folder)
    {
        folder = Utils.Text.Format("\"{0}\"", folder);
        switch (Application.platform)
        {
            case RuntimePlatform.WindowsEditor:
                Process.Start("Explorer.exe", folder.Replace('/', '\\'));
                break;

            case RuntimePlatform.OSXEditor:
                Process.Start("open", folder);
                break;

            default:
                throw new Exception($"Not support open folder on '{Application.platform}' platform.");
        }
    }
}
